function [out] = linebreak(in, brtype)
% break lines on input to 80 characters, with /r/n.....
%
if(nargin <= 1)
   brtype = 'regular'
end;
switch(brtype)
case 'html'
   br = '<br>';
otherwise
   br = [13];
end;

MAXL = 80;
if(nargin == 0)
   in = 'Note:  This is a good patch, but with small signal. The resting potential is -48mv before pulling the patch. The output gain is 10, and the holding current is -16pA.';
end;
if(length(in) < MAXL)
   out = in;
   return;
else
   out = [];
   sp1 = 1;
   while(length(in(sp1:end)) > MAXL)
      spaces = findstr(in(sp1:sp1+MAXL), ' ');
      if(isempty(spaces))
         if(in(sp1) == ' ')
            sp1 = sp1 + 1;
         end;
         out = strcat(out, in(sp1:end));
         out = strcat(out, br);
         sp1 = length(in);
      else
         u = max(spaces)+sp1-1;
         if(in(sp1) == ' ')
            sp1 = sp1 + 1;
         end;
         out = strcat(out, in(sp1:u));
         out = strcat(out, br);
         sp1 = u;
      end;
   end;
   if(sp1 < length(in))
         if(in(sp1) == ' ')
            sp1 = sp1 + 1;
         end;
      out = strcat(out, in(sp1:end));
      out = strcat(out, br);
   end;
end;

